package com.hissy.common.exprence;

import java.lang.reflect.Method;

/**
 * Created by zhangyanfei on 2018/11/1.
 *
 * @author zhangyanfei
 * @date 2018/11/01
 */
public class DemoClass {
    /**
     * 泛型方法  动态设置类型
     *
     * @param tClass
     * @param <T>
     * @return
     */
    public static <T> T getDemo(Class<T> tClass, String name)
        throws Exception {
        Object obj = tClass.getConstructor().newInstance();
        Method method = tClass.getMethod("setName",String.class);
        method.invoke(obj, name);
        return (T)obj;
    }
}
